<?php
/**
 *  NevuxBB - Free Forum Software
 *  Copyright (C) 2008, 2010 NevuxBB (No one specific author)*  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * ACP Index
 * File: index.php
 * Purpose: Managing the ACP
 * Todo: Complete the ACP
 *
 */

$acp = true;
require('../system/files/global.php');

// must be a valid session otherwise we wouldn't be here
// display the header data
$core_template_system->setvar(array('acp_page_title' => 'Home',
									'tab' => 'home',
									'show_full_header' => true));

// load the header
$core_template_system->pparse();

// load and display the main template body
$core_template_system->newTemplate(BASE_PATH . '/acp/template/main.html');
$core_template_system->pparse();

// set properties for main page
// obtain serial information
if(isset($acp_reserved_settings['serial_key']['data']) && !empty($acp_reserved_settings['serial_key']['data'])) {
	// has a key, display it
	$core_template_system->setvar(array('serial_key' => true,
										'serial_key_data' => $acp_reserved_settings['serial_key']['data']));
} else {
	// no key, show a link to get one
	$core_template_system->setvar(array('serial_key' => false));
}

// build the server info table data
$core_template_system->setvar(array('server_name' => $_SERVER['SERVER_NAME'],
									'server_software' => $_SERVER['SERVER_SOFTWARE']));

// load the error reports to show
$reports_results = Db_Abstraction::query("SELECT * FROM `nbb_error_reports` ORDER BY `err_id` DESC LIMIT 5;");

// loop through the error reports and create an array
$erro_reports = array(); $i = 0;
while($row = Db_Abstraction::fetch_assoc($reports_results)) {
	// expand the error reports array
	switch($row['err_sent']) {
		case 0:
			$rs = false;
			break;
		case 1:
			$rs = true;
			break;
	}
	
	// add to array
	$erro_reports[$i] = array('report_id' => $row['err_id'],
							  'report_data' => $row['err_data'],
							  'report_sent' => $rs);
	
	// increment i
	$i++;
}

// are there any results?
switch(mysql_num_rows($reports_results)) {
	case 0:
		// no results
		$core_template_system->setvar(array('error_reports_nresults' => true));
		
		// end
		break;
	default:
		// add error reports loop to the DB
		$core_template_system->setloop('error_reports', $erro_reports);
		
		// end
		break;
}

// now load our needed page
$core_template_system->newTemplate(BASE_PATH . '/acp/template/home_page.html');
$core_template_system->setvar(array());

// display the content
$core_template_system->pparse();
$core_template_system->reset();

// load the footer
$core_template_system->newTemplate(BASE_PATH . '/acp/template/footer.html');
$core_template_system->pparse();
?>